package com.wsx.java.boddy.empty;

import net.bytebuddy.ByteBuddy;
import net.bytebuddy.implementation.FixedValue;
import net.bytebuddy.matcher.ElementMatchers;

/**
 * @author wangshuaixin
 * @Title: com.wsx.java.boddy.empty.Empty
 * @Description: TODO
 * @date 2019/01/23
 */
public class Empty {

    public static void main(String[] args) throws Exception {

        String value = new ByteBuddy()
                .subclass(Object.class)
                .name("com.wsx.java.boddy.Type")
                .make()
                .load(Empty.class.getClassLoader())
                .getLoaded()
                .newInstance()
                .toString();

        System.out.println(value);


        value = new ByteBuddy()
                .subclass(Object.class)
                .name("com.wsx.java.boddy.TypeString")
                .method(ElementMatchers.named("toString").and(ElementMatchers.returns(String.class)).and(ElementMatchers.takesArguments(0)))
                .intercept(FixedValue.value("hello world!"))
                .make()
                .load(Empty.class.getClassLoader())
                .getLoaded()
                .newInstance()
                .toString();
        System.out.println(value);
    }
}
